﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMK.Framework.DataAccess;
using XMK.Tadong.Model;
using XMK.Utils;
using XMK.Framework.Model;
using XMK.Tadong.Model.Cond;
using System.Data;

namespace XMK.Tadong.Data
{
    public class Base_RM_SystemData
    {
         /// <summary>
        /// 数据库连接
        /// </summary>
        protected DbProvider dbProvider;

        public Base_RM_SystemData(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;
        }
        #region 菜单

        public List<Base_SysMenuInfo> GetMenuList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT Menu_Id,Menu_Name,ENMENU_NAME,Menu_Img,Menu_Type,TARGET,ParentId,
                      Menu_Type||'-'||SortCode AS Sort,SortCode,
                      NavigateUrl,CreateUserName,CreateDate,ModifyUserName,ModifyDate,ModifyUserID,CREATEUSERID 
                      FROM Base_SysMenu WHERE DeleteMark = 1 and Menu_Type !=3 ORDER BY SortCode ASC");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_SysMenuInfo> menuList = DbManager.GetInfoList<Base_SysMenuInfo>(cmd,
                delegate(out Base_SysMenuInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_SysMenuInfo
                    {

                        MENU_ID = ParseHelper.Parse<string>(row["MENU_ID"]),
                        PARENTID = ParseHelper.Parse<string>(row["PARENTID"]),
                        MENU_NAME = ParseHelper.Parse<string>(row["MENU_NAME"]),
                        ENMENU_NAME = ParseHelper.Parse<string>(row["ENMENU_NAME"]),
                       // MENU_TITLE = ParseHelper.Parse<string>(row["MENU_TITLE"]),
                        MENU_IMG = ParseHelper.Parse<string>(row["MENU_IMG"]),
                        MENU_TYPE = ParseHelper.Parse<decimal>(row["MENU_TYPE"]),
                        NAVIGATEURL = ParseHelper.Parse<string>(row["NAVIGATEURL"]),
                        TARGET = ParseHelper.Parse<string>(row["TARGET"]),
                       // ALLOWEDIT = ParseHelper.Parse<decimal>(row["ALLOWEDIT"]),
                       // ALLOWDELETE = ParseHelper.Parse<decimal>(row["ALLOWDELETE"]),
                        SORTCODE = ParseHelper.Parse<decimal>(row["SORTCODE"]),
                       // DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        CREATEDATE =ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                        CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["MODIFYDATE"])),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"])
                    };
                });
            return menuList;
        }

        public List<Base_SysMenuInfo> GetMenuBind()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM Base_SysMenu WHERE DeleteMark = 1 ORDER BY SortCode ASC");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_SysMenuInfo> menuList = DbManager.GetInfoList<Base_SysMenuInfo>(cmd,
                delegate(out Base_SysMenuInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_SysMenuInfo
                    {

                        MENU_ID = ParseHelper.Parse<string>(row["MENU_ID"]),
                        PARENTID = ParseHelper.Parse<string>(row["PARENTID"]),
                        MENU_NAME = ParseHelper.Parse<string>(row["MENU_NAME"]),
                        ENMENU_NAME = ParseHelper.Parse<string>(row["ENMENU_NAME"]),
                        // MENU_TITLE = ParseHelper.Parse<string>(row["MENU_TITLE"]),
                        MENU_IMG = ParseHelper.Parse<string>(row["MENU_IMG"]),
                        MENU_TYPE = ParseHelper.Parse<decimal>(row["MENU_TYPE"]),
                        NAVIGATEURL = ParseHelper.Parse<string>(row["NAVIGATEURL"]),
                        TARGET = ParseHelper.Parse<string>(row["TARGET"]),
                        // ALLOWEDIT = ParseHelper.Parse<decimal>(row["ALLOWEDIT"]),
                        // ALLOWDELETE = ParseHelper.Parse<decimal>(row["ALLOWDELETE"]),
                        // SORTCODE = ParseHelper.Parse<decimal>(row["SORTCODE"]),
                        // DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                        CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["MODIFYDATE"])),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"])
                    };
                });
            return menuList;
        }

        public List<Base_SysMenuInfo> GetSysMenuByButton(string Menu_Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM Base_SysMenu ");
            strSql.Append("WHERE ParentId =:p_Menu_Id ");
            strSql.Append("AND DELETEMARK = 1 AND Menu_Type = 3 ORDER BY SORTCODE ASC");
            
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "Menu_Id").ToArray();
            });
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(Menu_Id);
            List<Base_SysMenuInfo> menuList = DbManager.GetInfoList<Base_SysMenuInfo>(cmd,
                delegate(out Base_SysMenuInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_SysMenuInfo
                    {

                        MENU_ID = ParseHelper.Parse<string>(row["MENU_ID"]),
                        PARENTID = ParseHelper.Parse<string>(row["PARENTID"]),
                        MENU_NAME = ParseHelper.Parse<string>(row["MENU_NAME"]),
                        ENMENU_NAME = ParseHelper.Parse<string>(row["ENMENU_NAME"]),
                        // MENU_TITLE = ParseHelper.Parse<string>(row["MENU_TITLE"]),
                        MENU_IMG = ParseHelper.Parse<string>(row["MENU_IMG"]),
                        MENU_TYPE = ParseHelper.Parse<decimal>(row["MENU_TYPE"]),
                        NAVIGATEURL = ParseHelper.Parse<string>(row["NAVIGATEURL"]),
                        TARGET = ParseHelper.Parse<string>(row["TARGET"]),
                        // ALLOWEDIT = ParseHelper.Parse<decimal>(row["ALLOWEDIT"]),
                        // ALLOWDELETE = ParseHelper.Parse<decimal>(row["ALLOWDELETE"]),
                        // SORTCODE = ParseHelper.Parse<decimal>(row["SORTCODE"]),
                        // DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                        CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["MODIFYDATE"])),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"])
                    };
                });
            return menuList;
        }

        /// <summary>
        /// 取单条菜单
        /// </summary>
        /// <param name="MenuID"></param>
        /// <returns></returns>
        public Base_SysMenuInfo GetMenuByMenuID(string MenuID) {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM Base_SysMenu WHERE Menu_ID=:p_Menu_ID");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "Menu_ID").ToArray();
            });
            cmd.SetParamValues(MenuID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Base_SysMenuInfo menu = DbManager.GetInfo<Base_SysMenuInfo>(cmd,
                delegate(out Base_SysMenuInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_SysMenuInfo
                    {

                        MENU_ID = ParseHelper.Parse<string>(row["MENU_ID"]),
                        PARENTID = ParseHelper.Parse<string>(row["PARENTID"]),
                        MENU_NAME = ParseHelper.Parse<string>(row["MENU_NAME"]),
                        ENMENU_NAME = ParseHelper.Parse<string>(row["ENMENU_NAME"]),
                         MENU_TITLE = ParseHelper.Parse<string>(row["MENU_TITLE"]),
                        MENU_IMG = ParseHelper.Parse<string>(row["MENU_IMG"]),
                        MENU_TYPE = ParseHelper.Parse<decimal>(row["MENU_TYPE"]),
                        NAVIGATEURL = ParseHelper.Parse<string>(row["NAVIGATEURL"]),
                        TARGET = ParseHelper.Parse<string>(row["TARGET"]),
                        // ALLOWEDIT = ParseHelper.Parse<decimal>(row["ALLOWEDIT"]),
                        // ALLOWDELETE = ParseHelper.Parse<decimal>(row["ALLOWDELETE"]),
                         SORTCODE = ParseHelper.Parse<decimal>(row["SORTCODE"]),
                        // DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                        CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["MODIFYDATE"])),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"])
                    };
                });
            return menu;
        }

        /// <summary>
        /// 编辑菜单
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditMenuByMenuID(Base_SysMenuCond cond) {
            StringBuilder strSql = new StringBuilder();
            //action:0(删除)
            if (cond.action == 0) {
                strSql.Append("delete Base_SysMenu WHERE Menu_ID=:p_Menu_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "Menu_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.MENU_ID);
                return DbManager.ExecNonQuery(cmd)>0;
            }
            else if (cond.action == 1) {
                strSql.Append("update Base_SysMenu set SORTCODE=:p_SORTCODE,ParentId=:p_ParentId,Menu_Name=:p_Menu_Name,ENMENU_NAME=:p_ENMENU_NAME,Menu_title=:p_Menu_title,Navigateurl=:p_Navigateurl,Target=:p_Target  WHERE Menu_ID=:p_Menu_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "SORTCODE", "ParentId", "Menu_Name", "ENMENU_NAME", "Menu_title", "Navigateurl", "Target", "Menu_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.SORTCODE, cond.PARENTID, cond.MENU_NAME, cond.ENMENU_NAME, cond.MENU_TITLE, cond.NAVIGATEURL, cond.TARGET, cond.MENU_ID);
                return DbManager.ExecNonQuery(cmd) > 0;
            }
            else if (cond.action == 2) {
                strSql.Append("INSERT INTO BASE_SYSMENU ( MENU_ID ,PARENTID ,MENU_NAME ,ENMENU_NAME,MENU_TITLE ,MENU_TYPE ,NAVIGATEURL ,TARGET ,SORTCODE");
                strSql.Append(") VALUES (:p_MENU_ID ,:p_PARENTID ,:p_MENU_NAME ,:p_ENMENU_NAME,:p_MENU_TITLE,:p_MENU_TYPE ,:p_NAVIGATEURL ,:p_TARGET ,:p_SORTCODE)");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "MENU_ID", "PARENTID", "MENU_NAME", "ENMENU_NAME", "MENU_TITLE", "MENU_TYPE", "NAVIGATEURL", "TARGET", "SORTCODE").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(Guid.NewGuid().ToString(), cond.PARENTID, cond.MENU_NAME, cond.ENMENU_NAME, cond.MENU_TITLE, cond.MENU_TYPE, cond.NAVIGATEURL, cond.TARGET, cond.SORTCODE);
                return DbManager.ExecNonQuery(cmd) > 0;
            }
            
            return false;
        }
        #endregion
        /// <summary>
        /// 取用户菜单
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<Base_SysMenuInfo> GetUserMenuList(string USER_ACCOUNT)
        {
            
            DbCmdHelper cmd = new DbCmdHelper(dbProvider,"SP_QueryUserMenu",delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, false, "USER_ID").ToArray();
            });
            cmd.SetParamValues(USER_ACCOUNT);
            List<Base_SysMenuInfo> menuList = DbManager.GetInfoList<Base_SysMenuInfo>(cmd,
                delegate(out Base_SysMenuInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_SysMenuInfo
                    {

                        MENU_ID = ParseHelper.Parse<string>(row["MENU_ID"]),
                        PARENTID = ParseHelper.Parse<string>(row["PARENTID"]),
                        MENU_NAME = ParseHelper.Parse<string>(row["MENU_NAME"]),
                        ENMENU_NAME = ParseHelper.Parse<string>(row["ENMENU_NAME"]),
                        // MENU_TITLE = ParseHelper.Parse<string>(row["MENU_TITLE"]),
                        MENU_IMG = ParseHelper.Parse<string>(row["MENU_IMG"]),
                        MENU_TYPE = ParseHelper.Parse<decimal>(row["MENU_TYPE"]),
                        NAVIGATEURL = ParseHelper.Parse<string>(row["NAVIGATEURL"]),
                        TARGET = ParseHelper.Parse<string>(row["TARGET"]),

                        //CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                        //CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        //CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        //MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["MODIFYDATE"])),
                        //MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        //MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"])
                    };
                });
            return menuList;
        }

        

        /// <summary>
        /// 按钮列表
        /// </summary>
        /// <returns></returns>
        public List<Base_ButtonInfo> ButtonList(PageInfo pageInfo, OrderInfo order)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "sp_getpagebuttonlist", delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, true).ToArray();
            });
            cmd.SetParamValues(order, pageInfo);
            List<Base_ButtonInfo> buttonList = DbManager.GetPageInfos(cmd, pageInfo,
                delegate(out Base_ButtonInfo buttonInfo, DataRow row)
                {
                    buttonInfo = new Base_ButtonInfo
                    {

                        BUTTON_ID = ParseHelper.Parse<string>(row["BUTTON_ID"]),
                        BUTTON_NAME = ParseHelper.Parse<string>(row["BUTTON_NAME"]),
                        BUTTON_TITLE = ParseHelper.Parse<string>(row["BUTTON_TITLE"]),
                        
                        BUTTON_IMG = ParseHelper.Parse<string>(row["BUTTON_IMG"]),
                        BUTTON_CODE = ParseHelper.Parse<string>(row["BUTTON_CODE"]),
                        SORTCODE = ParseHelper.Parse<decimal>(row["SORTCODE"]),
                        BUTTON_TYPE = ParseHelper.Parse<string>(row["BUTTON_TYPE"]),
                        BUTTON_REMAK = ParseHelper.Parse<string>(row["BUTTON_REMAK"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        
                        CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["MODIFYDATE"])),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                       
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"])
                    };
                });
            return buttonList;
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns></returns>
        public List<Base_RolesInfo> RolesList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT Roles_ID, ParentId, Roles_Name, Roles_Remark, SortCode, DeleteMark, CreateDate,CreateUserName,CreateUserID,ModifyUserID,ModifyDate, ModifyUserName");
            strSql.Append(" FROM Base_Roles WHERE DeleteMark != 0 ORDER BY SortCode ASC");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_RolesInfo> menuList = DbManager.GetInfoList<Base_RolesInfo>(cmd,
                delegate(out Base_RolesInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_RolesInfo
                    {

                        ROLES_ID = ParseHelper.Parse<string>(row["Roles_ID"]),
                        PARENTID = ParseHelper.Parse<string>(row["ParentId"]),
                        ROLES_NAME = ParseHelper.Parse<string>(row["Roles_Name"]),
                        // MENU_TITLE = ParseHelper.Parse<string>(row["MENU_TITLE"]),
                        ROLES_REMARK = ParseHelper.Parse<string>(row["Roles_Remark"]),
                        SORTCODE = ParseHelper.Parse<decimal>(row["SortCode"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DeleteMark"]),


                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CreateDate"])),
                        CREATEUSERID = ParseHelper.Parse<string>(row["CreateUserID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CreateUserName"]),
                        MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["ModifyDate"])),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["ModifyUserID"]),
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["ModifyUserName"])
                    };
                });
            return menuList;
        }

        /// <summary>
        /// 取角色信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public Base_RolesInfo GetRolesByID(string ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT Roles_ID,Roles_Name,Roles_Remark,SORTCODE,PARENTID FROM Base_Roles  WHERE Roles_ID=:p_Roles_ID ");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "Roles_ID").ToArray();
            });
            cmd.SetParamValues(ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Base_RolesInfo roleinfo = DbManager.GetInfo<Base_RolesInfo>(cmd,
                delegate(out Base_RolesInfo roleInfo, DataRow row)
                {
                    roleInfo = new Base_RolesInfo
                    {
                        SORTCODE = ParseHelper.Parse<int>(row["SORTCODE"]),
                        PARENTID = ParseHelper.Parse<string>(row["PARENTID"]),
                        ROLES_ID = ParseHelper.Parse<string>(row["Roles_ID"]),
                        ROLES_NAME = ParseHelper.Parse<string>(row["Roles_Name"]),
                        ROLES_REMARK = ParseHelper.Parse<string>(row["Roles_Remark"]),
                    };
                });
            return roleinfo;
        }

        /// <summary>
        /// 绑定角色
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditRole(Base_RolesCond cond)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            //action:0(删除)
            if (cond.action == 0)
            {
                strSql.Append("delete BASE_ROLES WHERE ROLES_ID=:p_ROLES_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "ROLES_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.ROLES_ID);
                DbManager.ExecNonQuery(cmd) ;
                //删除用户角色
                strSql1.Append("delete BASE_USERROLE WHERE ROLES_ID=:p_ROLES_ID");
                DbCmdHelper cmd1 = new DbCmdHelper(dbProvider, strSql1.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "ROLES_ID").ToArray();
                    });
                cmd1.DbCmdInfo.CommandType = CommandType.Text;
                cmd1.SetParamValues(cond.ROLES_ID);
                return DbManager.ExecNonQuery(cmd1) > 0;
            }
            else if (cond.action == 1)
            {
                strSql.Append("update BASE_ROLES set PARENTID =:p_PARENTID,ROLES_NAME = :p_ROLES_NAME,ROLES_REMARK = :p_ROLES_REMARK,SORTCODE = :p_SORTCODE where ROLES_ID=:p_ROLES_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "PARENTID", "ROLES_NAME", "ROLES_REMARK", "SORTCODE", "ROLES_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.PARENTID, cond.ROLES_NAME, cond.ROLES_REMARK, cond.SORTCODE, cond.ROLES_ID);
                return DbManager.ExecNonQuery(cmd) > 0;
            }
            else if (cond.action == 2)
            {
                strSql.Append("INSERT INTO BASE_ROLES ( ROLES_ID ,PARENTID ,ROLES_NAME ,ROLES_REMARK ,SORTCODE");
                strSql.Append(") VALUES (:p_ROLES_ID ,:p_PARENTID ,:p_ROLES_NAME ,:p_ROLES_REMARK,:p_SORTCODE)");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "ROLES_ID", "PARENTID", "ROLES_NAME", "ROLES_REMARK", "SORTCODE").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(Guid.NewGuid().ToString(), cond.PARENTID, cond.ROLES_NAME, cond.ROLES_REMARK, cond.SORTCODE);
                return DbManager.ExecNonQuery(cmd) > 0;
            }

            return false;
        }
    }
}
